package com.example.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Controller
@RequestMapping("login")
public class LoginController {

    @RequestMapping("/loginUser")
    public String  login(String username, String password, HttpServletRequest request, HttpServletResponse response, RedirectAttributes
            redirectAttributes) throws Exception {

        if("admin".equals(username.trim()) && "admin".equals(password.trim())){
            request.getSession().setAttribute("Users","admin");
            return "redirect:/resume/queryAll";
        }else {
            response.setContentType("text/html;charset=utf-8");
            response.getWriter().write("账户错误,登陆失败");
        }
        return null;
    }

    @RequestMapping("toLogin")
    public String toLogin() {
        System.out.println("================++++++++++++++跳转登录页面");
        return "login";
    }
}
